﻿using FAP.GetComment.DTO;
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FAP.GetComment
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnGetComment_Click(object sender, EventArgs e)
        {
            string url = "http://fap.tonghophoanhao.com/showthread.php?9-Bai-post-1";
            var site = new HtmlWeb();
            var doc = site.Load(url);
            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//*[@id=\"postlist\"]");
            List<News> lst = new List<News>();
            if (nodes != null)
            {
                //string day = node.SelectNodes("tr[1]/td[1]")[0].InnerText.Trim();
                //string year = node.SelectNodes("tr[1]/td[2]")[0].InnerText.Trim();
                //string month = node.SelectNodes("tr[2]/td[1]")[0].InnerText.Trim();
                //model.Title = node.SelectNodes("tr[1]/td[3]")[0].InnerText.Trim().Replace("&nbsp;&nbsp;", "");
                //string temp = node.SelectNodes("tr[1]/td[3]/a")[0].Attributes["href"].Value;


                bool flag = false;
                News model = new News();
                foreach (var node in nodes)
                {
                    HtmlNodeCollection nodeList = node.SelectNodes("ol/li");
                    foreach (var item in nodeList)
                    {
                        model = new News();
                        if (!flag)
                        {
                            model.Title = item.SelectNodes("div[2]/div[2]/div[1]/h2[1]")[0].InnerText;
                            flag = true;
                        } model.Content = item.SelectNodes("div[2]/div[2]/div[1]/div[1]/div[1]/blockquote[1]")[0].InnerText;
                        lst.Add(model);
                    }
                }
            }
        }
    }
}
